package tools.fileup;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class UpUtil
{
  private HttpServletRequest request;

  public UpUtil(HttpServletRequest paramHttpServletRequest)
  {
    this.request = paramHttpServletRequest;
  }

  public String getSavePath(String paramString)
  {
    return this.request.getSession().getServletContext().getRealPath("/") + getServerFilaPath(paramString) + "/" + getUpFileName(paramString);
  }

  public String getServerFilaPath(String paramString)
  {
    String str1 = getUpFileName(paramString);
    if ((str1 != null) || (str1.equals("")))
      return null;
    int i = str1.lastIndexOf(".");
    if (i == -1)
      return null;
    String str2 = str1.substring(i + 1);
    if ((str2 != null) && (str2.equals("")))
    {
      str2 = str2.toLowerCase();
      if ((str2.equals("gif")) || (str2.equals("jpeg")) || (str2.equals("jpg")) || (str2.equals("png")))
        return getFiltTypePathByImg();
      return getFileTypePath();
    }
    return null;
  }

  public String getFileTypePath()
  {
    if (this.request.getParameter("fileSavePath") != null)
      return this.request.getParameter("fileSavePath").toString();
    return null;
  }

  public String getFiltTypePathByImg()
  {
    if (this.request.getParameter("fileSavePath") != null)
      return this.request.getParameter("fileSavePath").toString() + "/image";
    return null;
  }

  public String getUpFileName(String paramString)
  {
    if (this.request.getParameter(paramString) != null)
    {
      String str1 = this.request.getParameter(paramString).toString();
      String str2 = "";
      int i = str1.indexOf("/");
      if (i == -1)
        return null;
      if (i != -1)
      {
        str2 = str1.substring(i + 1);
      }
      else
      {
        i = str1.indexOf("\\");
        if (i == -1)
          return null;
        str2 = str1.substring(i + 1);
      }
      return str2;
    }
    return null;
  }
}

